5 #define D(x) cout << #x " = " << (x) << endl
10 int dist(int x1
, int y1
, int x2
, int y2
){
13 return dx
* dx
+ dy
* dy
;
19 typedef pair
<int, int> point
;
22 vector
<point
> people
, chairs
;
24 int someoneCloser(int guy
, int chair
){
25 int D
= dist(people
[guy
].first
, people
[guy
].second
, chairs
[chair
].first
, chairs
[chair
].second
);
26 for (int i
= 0; i
< people
.size(); ++i
){
27 if (i
== guy
) continue;
28 int d
= dist(people
[i
].first
, people
[i
].second
, chairs
[chair
].first
, chairs
[chair
].second
);
29 if (d
< D
) return true;
36 for (int i
= 0; i
< rows
; ++i
){
37 for (int j
= 0; j
< cols
; ++j
){
39 if (mat
[i
][j
] == 'X') people
.push_back(point(i
, j
));
40 if (mat
[i
][j
] == 'L') chairs
.push_back(point(i
, j
));
44 for (int i
= 0; i
< people
.size(); ++i
){
45 //figure out in what chair this guy sits
46 vector
<pair
<int, int> > options
;
47 for (int j
= 0; j
< chairs
.size(); ++j
){
48 options
.push_back(make_pair(dist(people
[i
].first
, people
[i
].second
, chairs
[j
].first
, chairs
[j
].second
), j
));
50 sort(options
.begin(), options
.end());
51 sits
[i
] = -1; //no chair, yet
52 for (int j
= 0; j
< options
.size(); ++j
){
53 if (someoneCloser(i
, j
)) continue;
55 sits
[i
] = options
[j
].second
;
61 for (int i
= 0; i
< people
.size(); ++i
){
62 cout
<< sits
[i
] << endl
;